package cn.lanqiao.controller;

import cn.lanqiao.dao.UserDao;
import cn.lanqiao.entity.User;
import cn.lanqiao.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

import static cn.lanqiao.util.Result.fail;
import static cn.lanqiao.util.Result.success;

@Controller
@RestController
@RequestMapping("/user") //虚拟路径||二级路径
public class UserController {

//    @RequestMapping(value = "/query",method = RequestMethod.GET)
    @GetMapping("/query")
    public ModelAndView query(String userName){
        List list = new UserDao().query("select id,user_name as userName,password from sys_user");
        return new ModelAndView("list","userList",list);
    }

    @GetMapping("/s/{pageSize}/n/{pageNum}")
    public void insert(@PathVariable("pageSize") int pageSize, @PathVariable("pageNum") int pageNum){
        System.out.println(pageSize);
        System.out.println(pageNum);
    }


    @PostMapping("/query2")
    public Result query2(@RequestBody User user){
        List list = new UserDao().query("select id,user_name as userName,password from sys_user");
        if(list != null){
            return success(list);
        }else{
            return fail(400,"查询失败");
        }
    }
}
